package b.g.b.h.l;

import androidx.constraintlayout.widget.ConstraintLayout;
import b.g.b.h.c;
import b.g.b.h.d;
import b.g.b.h.f;
import b.g.b.h.h;
import b.g.b.h.k;
import b.g.b.h.l.b.a;
import b.g.b.h.l.b.b;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;

/* compiled from: DependencyGraph */
public class e {
    public b.g.b.h.e a;
    public boolean b = true;
    public boolean c = true;
    public b.g.b.h.e d;
    public ArrayList<o> e = new ArrayList();
    public b f;
    public a g;
    public ArrayList<l> h;

    public e(b.g.b.h.e eVar) {
        ArrayList arrayList = new ArrayList();
        this.f = null;
        this.g = new a();
        this.h = new ArrayList();
        this.a = eVar;
        this.d = eVar;
    }

    public final void a(f fVar, int i, int i2, f fVar2, ArrayList<l> arrayList, l lVar) {
        o oVar = fVar.d;
        if (oVar.c == null) {
            b.g.b.h.e eVar = this.a;
            if (oVar != eVar.d && oVar != eVar.e) {
                if (lVar == null) {
                    lVar = new l(oVar, i2);
                    arrayList.add(lVar);
                }
                oVar.c = lVar;
                lVar.b.add(oVar);
                for (d dVar : oVar.h.k) {
                    if (dVar instanceof f) {
                        a((f) dVar, i, 0, fVar2, arrayList, lVar);
                    }
                }
                for (d dVar2 : oVar.i.k) {
                    if (dVar2 instanceof f) {
                        a((f) dVar2, i, 1, fVar2, arrayList, lVar);
                    }
                }
                if (i == 1 && (oVar instanceof m)) {
                    for (d dVar22 : ((m) oVar).k.k) {
                        if (dVar22 instanceof f) {
                            a((f) dVar22, i, 2, fVar2, arrayList, lVar);
                        }
                    }
                }
                for (f a : oVar.h.l) {
                    a(a, i, 0, fVar2, arrayList, lVar);
                }
                for (f a2 : oVar.i.l) {
                    a(a2, i, 1, fVar2, arrayList, lVar);
                }
                if (i == 1 && (oVar instanceof m)) {
                    for (f a22 : ((m) oVar).k.l) {
                        a(a22, i, 2, fVar2, arrayList, lVar);
                    }
                }
            }
        }
    }

    public final boolean b(b.g.b.h.e eVar) {
        k kVar = eVar;
        d.a aVar = d.a.MATCH_CONSTRAINT;
        d.a aVar2 = d.a.WRAP_CONTENT;
        d.a aVar3 = d.a.FIXED;
        Iterator it = kVar.l0.iterator();
        while (it.hasNext()) {
            d dVar = (d) it.next();
            d.a[] aVarArr = dVar.O;
            d.a aVar4 = aVarArr[0];
            d.a aVar5 = aVarArr[1];
            if (dVar.c0 == 8) {
                dVar.a = true;
            } else {
                float f = dVar.q;
                if (f < 1.0f && aVar4 == aVar) {
                    dVar.l = 2;
                }
                float f2 = dVar.t;
                if (f2 < 1.0f && aVar5 == aVar) {
                    dVar.m = 2;
                }
                if (dVar.S > 0.0f) {
                    if (aVar4 == aVar && (aVar5 == aVar2 || aVar5 == aVar3)) {
                        dVar.l = 3;
                    } else if (aVar5 == aVar && (aVar4 == aVar2 || aVar4 == aVar3)) {
                        dVar.m = 3;
                    } else if (aVar4 == aVar && aVar5 == aVar) {
                        if (dVar.l == 0) {
                            dVar.l = 3;
                        }
                        if (dVar.m == 0) {
                            dVar.m = 3;
                        }
                    }
                }
                if (aVar4 == aVar && dVar.l == 1 && (dVar.D.f == null || dVar.F.f == null)) {
                    aVar4 = aVar2;
                }
                d.a aVar6 = (aVar5 == aVar && dVar.m == 1 && (dVar.E.f == null || dVar.G.f == null)) ? aVar2 : aVar5;
                k kVar2 = dVar.d;
                kVar2.d = aVar4;
                int i = dVar.l;
                kVar2.a = i;
                m mVar = dVar.e;
                mVar.d = aVar6;
                int i2 = dVar.m;
                mVar.a = i2;
                aVar5 = d.a.MATCH_PARENT;
                int r;
                if ((aVar4 == aVar5 || aVar4 == aVar3 || aVar4 == aVar2) && (aVar6 == aVar5 || aVar6 == aVar3 || aVar6 == aVar2)) {
                    int r2;
                    d.a aVar7;
                    int l;
                    r = dVar.r();
                    if (aVar4 == aVar5) {
                        r2 = (eVar.r() - dVar.D.g) - dVar.F.g;
                        aVar7 = aVar3;
                    } else {
                        aVar7 = aVar4;
                        r2 = r;
                    }
                    int l2 = dVar.l();
                    if (aVar6 == aVar5) {
                        l = (eVar.l() - dVar.E.g) - dVar.G.g;
                        aVar5 = aVar3;
                    } else {
                        l = l2;
                        aVar5 = aVar6;
                    }
                    d dVar2 = dVar;
                    f(dVar, aVar7, r2, aVar5, l);
                    dVar2.d.e.c(dVar2.r());
                    dVar2.e.e.c(dVar2.l());
                    dVar2.a = true;
                } else {
                    d.a[] aVarArr2;
                    if (aVar4 == aVar && (aVar6 == aVar2 || aVar6 == aVar3)) {
                        if (i == 3) {
                            if (aVar6 == aVar2) {
                                f(dVar, aVar2, 0, aVar2, 0);
                            }
                            int l3 = dVar.l();
                            f(dVar, aVar3, (int) ((((float) l3) * dVar.S) + 0.5f), aVar3, l3);
                            dVar.d.e.c(dVar.r());
                            dVar.e.e.c(dVar.l());
                            dVar.a = true;
                        } else if (i == 1) {
                            f(dVar, aVar2, 0, aVar6, 0);
                            dVar.d.e.m = dVar.r();
                        } else if (i == 2) {
                            aVarArr2 = kVar.O;
                            if (aVarArr2[0] == aVar3 || aVarArr2[0] == aVar5) {
                                f(dVar, aVar3, (int) ((f * ((float) eVar.r())) + 0.5f), aVar6, dVar.l());
                                dVar.d.e.c(dVar.r());
                                dVar.e.e.c(dVar.l());
                                dVar.a = true;
                            }
                        } else {
                            c[] cVarArr = dVar.L;
                            if (cVarArr[0].f == null || cVarArr[1].f == null) {
                                f(dVar, aVar2, 0, aVar6, 0);
                                dVar.d.e.c(dVar.r());
                                dVar.e.e.c(dVar.l());
                                dVar.a = true;
                            }
                        }
                    }
                    if (aVar6 == aVar && (aVar4 == aVar2 || aVar4 == aVar3)) {
                        if (i2 == 3) {
                            if (aVar4 == aVar2) {
                                f(dVar, aVar2, 0, aVar2, 0);
                            }
                            r = dVar.r();
                            float f3 = dVar.S;
                            if (dVar.T == -1) {
                                f3 = 1.0f / f3;
                            }
                            f(dVar, aVar3, r, aVar3, (int) ((((float) r) * f3) + 0.5f));
                            dVar.d.e.c(dVar.r());
                            dVar.e.e.c(dVar.l());
                            dVar.a = true;
                        } else if (i2 == 1) {
                            f(dVar, aVar4, 0, aVar2, 0);
                            dVar.e.e.m = dVar.l();
                        } else if (i2 == 2) {
                            aVarArr2 = kVar.O;
                            if (aVarArr2[1] == aVar3 || aVarArr2[1] == aVar5) {
                                f(dVar, aVar4, dVar.r(), aVar3, (int) ((f2 * ((float) eVar.l())) + 0.5f));
                                dVar.d.e.c(dVar.r());
                                dVar.e.e.c(dVar.l());
                                dVar.a = true;
                            }
                        } else {
                            c[] cVarArr2 = dVar.L;
                            if (cVarArr2[2].f == null || cVarArr2[3].f == null) {
                                f(dVar, aVar2, 0, aVar6, 0);
                                dVar.d.e.c(dVar.r());
                                dVar.e.e.c(dVar.l());
                                dVar.a = true;
                            }
                        }
                    }
                    if (aVar4 == aVar && aVar6 == aVar) {
                        if (i == 1 || i2 == 1) {
                            f(dVar, aVar2, 0, aVar2, 0);
                            dVar.d.e.m = dVar.r();
                            dVar.e.e.m = dVar.l();
                        } else if (i2 == 2 && i == 2) {
                            aVarArr = kVar.O;
                            if ((aVarArr[0] == aVar3 || aVarArr[0] == aVar3) && (aVarArr[1] == aVar3 || aVarArr[1] == aVar3)) {
                                f(dVar, aVar3, (int) ((f * ((float) eVar.r())) + 0.5f), aVar3, (int) ((f2 * ((float) eVar.l())) + 0.5f));
                                dVar.d.e.c(dVar.r());
                                dVar.e.e.c(dVar.l());
                                dVar.a = true;
                            }
                        }
                    }
                }
            }
        }
        return false;
    }

    public void c() {
        ArrayList arrayList = this.e;
        arrayList.clear();
        this.d.d.f();
        this.d.e.f();
        arrayList.add(this.d.d);
        arrayList.add(this.d.e);
        Iterator it = this.d.l0.iterator();
        Collection collection = null;
        while (it.hasNext()) {
            d dVar = (d) it.next();
            if (dVar instanceof f) {
                arrayList.add(new i(dVar));
            } else {
                if (dVar.w()) {
                    if (dVar.b == null) {
                        dVar.b = new c(dVar, 0);
                    }
                    if (collection == null) {
                        collection = new HashSet();
                    }
                    collection.add(dVar.b);
                } else {
                    arrayList.add(dVar.d);
                }
                if (dVar.x()) {
                    if (dVar.c == null) {
                        dVar.c = new c(dVar, 1);
                    }
                    if (collection == null) {
                        collection = new HashSet();
                    }
                    collection.add(dVar.c);
                } else {
                    arrayList.add(dVar.e);
                }
                if (dVar instanceof h) {
                    arrayList.add(new j(dVar));
                }
            }
        }
        if (collection != null) {
            arrayList.addAll(collection);
        }
        it = arrayList.iterator();
        while (it.hasNext()) {
            ((o) it.next()).f();
        }
        Iterator it2 = arrayList.iterator();
        while (it2.hasNext()) {
            o oVar = (o) it2.next();
            if (oVar.b != this.d) {
                oVar.d();
            }
        }
        this.h.clear();
        l.c = 0;
        e(this.a.d, 0, this.h);
        e(this.a.e, 1, this.h);
        this.b = false;
    }

    public final int d(b.g.b.h.e eVar, int i) {
        e eVar2 = this;
        d dVar = eVar;
        int i2 = i;
        int size = eVar2.h.size();
        long j = 0;
        long j2 = 0;
        int i3 = 0;
        while (i3 < size) {
            l lVar = (l) eVar2.h.get(i3);
            o oVar = lVar.a;
            if (oVar instanceof c) {
                if (((c) oVar).f != i2) {
                    j = Math.max(j, j2);
                    i3++;
                    j2 = 0;
                    eVar2 = this;
                    dVar = eVar;
                }
            } else if (i2 == 0) {
                if (!(oVar instanceof k)) {
                    j = Math.max(j, j2);
                    i3++;
                    j2 = 0;
                    eVar2 = this;
                    dVar = eVar;
                }
            } else if (!(oVar instanceof m)) {
                j = Math.max(j, j2);
                i3++;
                j2 = 0;
                eVar2 = this;
                dVar = eVar;
            }
            f fVar = (i2 == 0 ? dVar.d : dVar.e).h;
            f fVar2 = (i2 == 0 ? dVar.d : dVar.e).i;
            boolean contains = oVar.h.l.contains(fVar);
            boolean contains2 = lVar.a.i.l.contains(fVar2);
            long j3 = lVar.a.j();
            o oVar2;
            if (contains && contains2) {
                long b = lVar.b(lVar.a.h, j2);
                j2 = lVar.a(lVar.a.i, j2);
                b -= j3;
                o oVar3 = lVar.a;
                int i4 = oVar3.i.f;
                if (b >= ((long) (-i4))) {
                    b += (long) i4;
                }
                long j4 = (-j2) - j3;
                j2 = (long) oVar3.h.f;
                j4 -= j2;
                if (j4 >= j2) {
                    j4 -= j2;
                }
                d dVar2 = oVar3.b;
                Objects.requireNonNull(dVar2);
                float f = i2 == 0 ? dVar2.Z : i2 == 1 ? dVar2.a0 : -1.0f;
                float f2 = (float) (f > 0.0f ? (long) ((((float) b) / (1.0f - f)) + (((float) j4) / f)) : 0);
                b = (((long) ((f2 * f) + 0.5f)) + j3) + ((long) c.b.a.a.a.a(1.0f, f, f2, 0.5f));
                oVar2 = lVar.a;
                j2 = (((long) oVar2.h.f) + b) - ((long) oVar2.i.f);
                j = Math.max(j, j2);
                i3++;
                j2 = 0;
                eVar2 = this;
                dVar = eVar;
            } else {
                f fVar3;
                if (contains) {
                    fVar3 = lVar.a.h;
                    j2 = Math.max(lVar.b(fVar3, (long) fVar3.f), ((long) lVar.a.h.f) + j3);
                } else if (contains2) {
                    fVar3 = lVar.a.i;
                    j2 = Math.max(-lVar.a(fVar3, (long) fVar3.f), ((long) (-lVar.a.i.f)) + j3);
                } else {
                    oVar2 = lVar.a;
                    j2 = (oVar2.j() + ((long) oVar2.h.f)) - ((long) lVar.a.i.f);
                }
                j = Math.max(j, j2);
                i3++;
                j2 = 0;
                eVar2 = this;
                dVar = eVar;
            }
        }
        return (int) j;
    }

    public final void e(o oVar, int i, ArrayList<l> arrayList) {
        for (d dVar : oVar.h.k) {
            if (dVar instanceof f) {
                a((f) dVar, i, 0, oVar.i, arrayList, null);
            } else if (dVar instanceof o) {
                a(((o) dVar).h, i, 0, oVar.i, arrayList, null);
            }
        }
        for (d dVar2 : oVar.i.k) {
            if (dVar2 instanceof f) {
                a((f) dVar2, i, 1, oVar.h, arrayList, null);
            } else if (dVar2 instanceof o) {
                a(((o) dVar2).i, i, 1, oVar.h, arrayList, null);
            }
        }
        if (i == 1) {
            for (d dVar3 : ((m) oVar).k.k) {
                if (dVar3 instanceof f) {
                    a((f) dVar3, i, 2, null, arrayList, null);
                }
            }
        }
    }

    public final void f(d dVar, d.a aVar, int i, d.a aVar2, int i2) {
        a aVar3 = this.g;
        aVar3.a = aVar;
        aVar3.b = aVar2;
        aVar3.c = i;
        aVar3.d = i2;
        ((ConstraintLayout.a) this.f).b(dVar, aVar3);
        dVar.M(this.g.e);
        dVar.H(this.g.f);
        a aVar4 = this.g;
        dVar.y = aVar4.h;
        dVar.E(aVar4.g);
    }

    public void g() {
        d.a aVar = d.a.FIXED;
        d.a aVar2 = d.a.MATCH_CONSTRAINT;
        Iterator it = this.a.l0.iterator();
        while (it.hasNext()) {
            d dVar = (d) it.next();
            if (!dVar.a) {
                d.a[] aVarArr = dVar.O;
                int i = 0;
                d.a aVar3 = aVarArr[0];
                d.a aVar4 = aVarArr[1];
                int i2 = dVar.l;
                int i3 = dVar.m;
                d.a aVar5 = d.a.WRAP_CONTENT;
                Object obj = (aVar3 == aVar5 || (aVar3 == aVar2 && i2 == 1)) ? 1 : null;
                if (aVar4 == aVar5 || (aVar4 == aVar2 && i3 == 1)) {
                    i = 1;
                }
                g gVar = dVar.d.e;
                boolean z = gVar.j;
                g gVar2 = dVar.e.e;
                boolean z2 = gVar2.j;
                if (z && z2) {
                    f(dVar, aVar, gVar.g, aVar, gVar2.g);
                    dVar.a = true;
                } else if (z && i != 0) {
                    f(dVar, aVar, gVar.g, aVar5, gVar2.g);
                    if (aVar4 == aVar2) {
                        dVar.e.e.m = dVar.l();
                    } else {
                        dVar.e.e.c(dVar.l());
                        dVar.a = true;
                    }
                } else if (z2 && obj != null) {
                    f(dVar, aVar5, gVar.g, aVar, gVar2.g);
                    if (aVar3 == aVar2) {
                        dVar.d.e.m = dVar.r();
                    } else {
                        dVar.d.e.c(dVar.r());
                        dVar.a = true;
                    }
                }
                if (dVar.a) {
                    g gVar3 = dVar.e.l;
                    if (gVar3 != null) {
                        gVar3.c(dVar.W);
                    }
                }
            }
        }
    }
}
